<?php
require_once(dirname(dirname(dirname(__FILE__))) . '/app.php');

need_manager();
need_auth('order');



$condition = array(
	
);



/* filter */
$uemail = strval($_GET['uemail']);
if ($uemail) {
	
	$uuser = Table::Fetch('user', $uemail, 'username');
	if($uuser) $condition['user_id'] = $uuser['id'];
	else $uemail = null;
}
$id = abs(intval($_GET['id'])); 
if ($id) $condition['id'] = $id;


$cbday = strval($_GET['cbday']);
$ceday = strval($_GET['ceday']);

if ($cbday) { 
	$cbtime = strtotime($cbday);
	$condition[] = "addtime >= '{$cbtime}'";
}
if ($ceday) { 
	$cetime = strtotime($ceday);
	$condition[] = "addtime <= '{$cetime}'";
}
$is_fahuo = -1;
//is_fahuo  -1 0 1 2 
if(isset($_GET['is_fahuo']) && $_GET['is_fahuo']>=0 )
{
	$is_fahuo = intval($_GET['is_fahuo']);
	$condition['state'] = $is_fahuo;
}
/* end fiter */

$count = Table::Count('tixian_order', $condition);
list($pagesize, $offset, $pagestring) = pagestring($count, 20);

$orders = DB::LimitQuery('tixian_order', array(
	'condition' => $condition,
	'order' => 'ORDER BY id DESC',
	'size' => $pagesize,
	'offset' => $offset,
));

foreach($orders as $key =>$val)
{
	
}

$pay_ids = Utility::GetColumn($orders, 'pay_id');
$pays = Table::Fetch('pay', $pay_ids);

$user_ids = Utility::GetColumn($orders, 'user_id');
$users = Table::Fetch('user', $user_ids);

$team_ids = Utility::GetColumn($orders, 'team_id');
$teams = Table::Fetch('team', $team_ids);

include template('manage_order_tixian');
